home *** CD-ROM | disk | FTP | other *** search
- ' ----------------------------------------------------------------------
- ' Processing the CLI argument(s) string
- ' (the program will return the #p% arg asked and
- ' will be remove the leading/trailing spaces
- ' like the final space inserted by KingCON...
- ' and the initial/final quotation marks).
- ' New feature requested by Mr Goertz for the ImageDTInfo project :)
- '
- ' ------------
- ' Procesando la cadena de argumento(s) CLI
- ' (el programa devolverá el argumento nº "p%" pedido
- ' y eliminará los espacios iniciales y finales
- ' como el insertado al final por KingCON...
- ' y las comillas iniciales/finales).
- ' Nueva prestación pedida por el
- ' Sr. Goertz para el proyecto ImageDTInfo :).
- ' ------------------------------------------------------------------------
- ' Arguments/Argumentos
- '
- ' cad$ = Cadena de argumentos CLI/Shell
- ' (habitualmente obtenida con COMMAND$)
- '
- ' CLI/Shell arguments string
- ' (habitually the string returned by COMMAND$)
- '
- ' p% = Nº (posición) del argumento pedido. Número entero >=1.
- '
- ' The argument asked (position). Integer number >=1.
-
- ' Returned/Devuelve...
- '
- ' O una cadena nula (no existe el argumento
- ' nº "p%" pedido) O el argumento solicitado.
- '
- ' Or a null string (don't exists
- ' the argument #"p%") OR the argument requested
- '
- ' -----------------------------------------------------------------------
-
- FUNCTION getarg$(cad$,p%)
- LOCAL num%,quotes%,char%,cadtmp$,a%
-
- getarg$=""
-
- ' ---------------- Anti bad coders };D. Remember! p% must be >=1 !! ------------
- ' - Protección contra malos programadores };D. Recuerde ¡¡ p% ha de ser >=1 !! -
- ' ------------------------------------------------------------------------------
- IF p% <=0 THEN p%=1
-
- WHILE cad$ <> ""
-
- ' --------- Removing not necesary spaces (start/end) -----------
- ' - Suprimir espacios innecesarios (inicio/final de la cadena) -
- ' --------------------------------------------------------------
- cad$=LTRIM$(RTRIM$(cad$))
-
- num% = 1
- cadtmp$ = ""
- quotes% = 0
-
- FOR a%=1 TO LEN(cad$)
-
- char%=ASC(MID$(cad$,a%,1))
-
- SELECT CASE char%
-
- ' ------ Modifying quotes status -------
- ' - Modificando estado de las comillas -
- ' --------------------------------------
- CASE 34
- quotes% = NOT quotes%
-
- ' -- Spaces/ Espacios --
- ' ----------------------
- CASE 32
- IF quotes% = 0 THEN
- ' --- The space is an arguments separator ---
- ' - El espacio es un separador de argumentos-
- ' -------------------------------------------
- IF num%=p% THEN
- ' --------- Parse arg asked... end ---------
- ' - Procesado argumento pedido... terminar -
- ' ------------------------------------------
- EXIT FOR
- ELSE
- '-- Parse the next character (and argument) --
- '- Procesar siguiente carácter (y argumento) -
- ' --------------------------------------------
- num%=num%+1%
- EXIT SELECT
- END IF
- ELSE
- ' --------- To preserve space for the argument asked (quoted) ---------
- ' -- Preservar espacios del argumento pedido si están entre comillas --
- ' ---------------------------------------------------------------------
- IF num%=p% THEN cadtmp$=cadtmp$+CHR$(char%)
- END IF
-
- ' --- Preserve others characters (only for the argument asked) ----
- ' - Preservar el resto de los caracteres para el argumento pedido -
- ' -----------------------------------------------------------------
- CASE ELSE
- IF num%=p% THEN cadtmp$=cadtmp$+CHR$(char%)
-
- END SELECT
-
- NEXT a%
-
- cad$ = cadtmp$
-
- ' --------------- Template info ---------------
- ' - Información sobre la sintaxis del comando -
- ' ---------------------------------------------
-
- IF cad$ = "?" THEN
-
- PRINT CadLc$(MSG_TEMPLATE&);"/A: ";
- INPUT "",cad$
-
- ELSE
-
- ' ---------- Exit point if cad$<>"" -----------
- ' - Punto de salida de la función si cad$<>"" -
- ' ---------------------------------------------
- getarg$=cad$
- EXIT WHILE
-
- END IF
-
- WEND
-
- ' ---------- Exit point if cad$="" -----------
- ' - Punto de salida de la función si cad$="" -
- ' --------------------------------------------
- END FUNCTION
-